package com.wb.mas.business;

import android.text.TextUtils;

import com.blankj.utilcode.util.SPUtils;
import com.wb.mas.app.SPKeys;

import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by goldze on 2017/5/10.
 */
public class HeaderInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request()
                .newBuilder();
        String token = SPUtils.getInstance().getString(SPKeys.KEY_OF_TOKEN);
        if (!TextUtils.isEmpty(token)) {
            builder.addHeader("Authorization", token).build();
        }
        //请求信息
        return chain.proceed(builder.build());
    }
}